package com.smartum.mpr.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.types.Side;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;
import com.smartum.mpr.client.Authorization;
import com.smartum.mpr.client.event.TabClickHandler;
import com.smartum.mpr.client.event.WindowResizeHandler;
import com.smartum.mpr.client.presenter.ContentViewerPresenter;

/**
 */
public class ContentViewerView extends HLayout implements ContentViewerPresenter.Display {

    private final TabSet topTabSet;
    private final Tab newsTab;
    private final Tab itemsTab;
    private final Tab jobsTab;

    public ContentViewerView() {
        final Authorization authorizationBundle = com.google.gwt.core.shared.GWT.create(Authorization.class);

        setStyleName("tabPanel");
        setHeight(Window.getClientHeight() - 53);

        topTabSet = new TabSet();
        topTabSet.setTabBarPosition(Side.TOP);
        topTabSet.setTabBarAlign(Side.RIGHT);
        topTabSet.setWidth(Window.getClientWidth());
        topTabSet.selectTab(0);
        //TODO: get 53 from element. Remove hardcode
        topTabSet.setHeight(Window.getClientHeight() - 53);

        final Tab imagesTab = new Tab(authorizationBundle.imageTab(), "tabs/images.png");
        ImageViewerView imageViewerView = new ImageViewerView();
        imagesTab.setPane(imageViewerView);

        itemsTab = new Tab(authorizationBundle.itemsTab(), "tabs/items.png");
        jobsTab = new Tab(authorizationBundle.jobsTab(), "tabs/jobs.png");
        newsTab = new Tab(authorizationBundle.newsTab(), "tabs/news.png");

        topTabSet.addTab(imagesTab);
        topTabSet.addTab(newsTab);
        topTabSet.addTab(itemsTab);
        topTabSet.addTab(jobsTab);

        final WindowResizeHandler wrapperResizeHandler = new WindowResizeHandler(this, 53,
                0, true);
        Window.addResizeHandler(wrapperResizeHandler);

        final WindowResizeHandler tabPanelResizeHandler = new WindowResizeHandler(topTabSet, 53,
                0, true);
        Window.addResizeHandler(tabPanelResizeHandler);
        addMember(topTabSet);
    }

    @Override
    public TabSet getTabSet() {
        return this.topTabSet;
    }

    public Widget getContentViewerWidget() {
        return this;
    }

    public Tab getNewsTab() {
        return newsTab;
    }

    public Tab getItemsTab() {
        return itemsTab;
    }

    public Tab getJobsTab() {
        return jobsTab;
    }
}
